package com.lx.shopping.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.lx.bilibili.entity.Order;
import com.lx.bilibili.entity.OrderEx;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author lx
 * @since 2025-04-13
 */
public interface OrderMapper extends BaseMapper<Order> {

    // 1. 先查询当前最大ID
    @Select("SELECT MAX(id)+1 FROM orders")
    Integer getNextAutoIncrementValue();

    // 2. 再设置自增值
    @Update("ALTER TABLE orders AUTO_INCREMENT = #{value}")
    void setAutoIncrement(@Param("value") Integer value);

    @Select("SELECT\n" +
            "	a.*,\n" +
            "	b.image,\n" +
            "	b.NAME \n" +
            "FROM\n" +
            "	orders a,\n" +
            "	product b \n" +
            "WHERE\n" +
            "	a.pid = b.id \n" +
            "	AND a.uid = #{uid} limit #{page}, #{size}")
    List<OrderEx> getOrderByUserId(int uid, int page, int size);
}
